package com.project.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.project.bean.ProductBean;
import com.project.mapper.IProductMapper;
import com.project.service.IProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.time.LocalDate;

/**
 * @author lyl
 * description:
 */
@Service
@Transactional
public class ProductServiceImpl implements IProductService {
    @Autowired
    private IProductMapper iProductMapper;

    @Override
    public PageInfo<ProductBean> findByPage(int pageNo, String productName, LocalDate startDate, LocalDate endDate, String productStatue) {
        PageHelper.startPage(pageNo, 3);
        PageInfo<ProductBean> info = PageInfo.of(iProductMapper.findByPage(productName, startDate, endDate, productStatue));
        return info;
    }


    @Override
    public ProductBean findByProductId(int productId) {
        return iProductMapper.findByProductId(productId);
    }

    @Override
    public void updateProductStatue(int productId, String productStatue) {
        iProductMapper.updateProductStatue(productId, productStatue);
    }

    @Override
    public void updateProductPrice(int productId, int productPrice) {
        iProductMapper.updateProductPrice(productId, productPrice);
    }

    @Override
    public void addNewProduct(ProductBean productBean) {
        iProductMapper.addNewProduct(productBean);
    }

}
